﻿using AttributeDemo.CustomAttribute;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace AttributeDemo.UseAttribute
{
    public static class UseSummaryAttribute
    {
        public static string GetSummary(this SexEnum sexEnum)
        {
            Type type = sexEnum.GetType();
            var field = type.GetField(sexEnum.ToString());
            if (field.IsDefined(typeof(SummaryAttribute), true))
            {
                SummaryAttribute attribute = (SummaryAttribute)field.GetCustomAttribute(typeof(SummaryAttribute), true);
                return attribute.Summary;
            }
            else
            {
                return sexEnum.ToString();
            }
        }
    }
}
